package com.kotlin.demo.net

import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.kotlin.demo.CommViewModel
import com.kotlin.demo.UserViewModel
import com.kotlin.demo.bean.ArticleData
import kotlinx.coroutines.Deferred
import org.koin.android.viewmodel.ext.koin.viewModel
import org.koin.dsl.module.module
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET

/**
 * author : fang.zhang
 * e-mail : initzf@126.com
 * date   : 2019-11-19
 * desc   :
 */
object RetrofitClient {
    val BASE_URL = "https://wanandroid.com"

    val api by lazy {
        val retrofit = Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(CoroutineCallAdapterFactory.invoke())
            .build()
        return@lazy retrofit.create(RequestService::class.java)
    }
}

interface RequestService {

    @GET("wxarticle/chapters/json")
    suspend fun getData(): ArticleData

    @GET("wxarticle/chapters/json")
    suspend fun getData1(): ArticleData

    @GET("wxarticle/chapters/json")
    fun getData4(): Deferred<ArticleData>


    @GET("wxarticle/chapters/json")
    fun getData3(): Call<ArticleData>

    @GET("wxarticle/chapters/json")
    fun getData2(): Call<ArticleData>
}

val appModule = module {

    viewModel { CommViewModel() }
    viewModel { UserViewModel() }
}